<?php

namespace Kuoqi;

use \Kuoqi\FileDriver;
use \Kuoqi\Route;

/**
 * API 常用对外控件的安装
 * Class Api
 * @package Kuoqi
 * User kuoqi
 * Datetime 2022/3/30 10:03
 * Remark
 */
class Api{

    /**
     * 文件完整路径，{@APP_ROOT}，标识app_ROOT。{@ROOT}标识root
     * @var string
     * User kuoqi
     * Datetime 2022/3/30 10:32
     * Remark
     */
    public $index_root = '';


    /**
     * 数据验证信息
     * @var bool
     * User kuoqi
     * Datetime 2022/3/30 10:12
     * Remark
     */
    public $is_valied = true;

    /**
     * 错误信息内容
     * @var string
     * User kuoqi
     * Datetime 2022/3/30 10:15
     * Remark
     */
    public $errmsg = '';

    /**
     * 服务端对象放到这个里面
     * @var string
     * User kuoqi
     * Datetime 2022/3/30 11:16
     * Remark
     */
    public $server = '';


    /**
     * App constructor.
     */
    public function __construct()
    {
        //todo--

    }

    /**
     * 初始化方法
     * User kuoqi
     * Datetime 2022/3/30 10:11
     * Remark
     */
    public function init(){
        $file = Route::str2rootpath($this->index_root);
        if(!is_file($file)){
            $this->errmsg = '引入扩展失败 : '.$this->index_root;
            $this->is_valied = false;
            return ;
        }
        include_once $file;
        return $this;
    }

    /**
     * 是否验证信息
     * @return mixed
     * User kuoqi
     * Datetime 2022/3/30 10:12
     * Remark
     */
    public function isValied(){
        return $this->is_valied;
    }

    /**
     * 获取当前错误信息
     * @return mixed
     * User kuoqi
     * Datetime 2022/3/30 10:12
     * Remark
     */
    public function getError(){
        return $this->errmsg;
    }

    /**
     * __destruct system
     */
    public function __destruct()
    {
        // TODO: Implement __destruct() method.
    }

}

